package com.xlh.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Objects;

/**
 * 资源关系类型
 * <p>
 * Created by lx on 2019/1/28.
 */
@Getter
@AllArgsConstructor
public enum ResourceRelationTypeEnum {

    CHAPTER(1, "章节"),
    COURSE(2, "课程"),
    STEP(4, "步骤");

    private int code;

    private String message;

    public static ResourceRelationTypeEnum getByCode(int code) {
        for (ResourceRelationTypeEnum typeEnum : ResourceRelationTypeEnum.values()) {
            if (Objects.equals(typeEnum.getCode(), code)) {
                return typeEnum;
            }
        }
        return null;
    }

    public static String getMessageByCode(int code) {
        ResourceRelationTypeEnum typeEnum = getByCode(code);
        return typeEnum == null ? null : typeEnum.getMessage();
    }

}
